package com.gm.manager.module.login.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gm.manager.common.entity.db.UserDaoEntity;
import com.gm.manager.module.login.entity.LoginBack;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author zhuZhaoYang
 * @date 2021/8/7 14:25
 */
@Mapper
public interface UserMapper extends BaseMapper<UserDaoEntity> {

    /**
     * 根据id返回登录信息
     *
     * @param id userId
     * @return 登录信息
     */
    @Select("select id, username, token, name, " +
            "(select actor.name from actor where actor.id=actorId) as actor," +
            "(select department.name from department where department.id=departmentId) as department," +
            " telNumber from user where id=#{id}")
    LoginBack getInfoById(Integer id);

    /**
     * 清空token
     *
     * @param id userId
     * @return 是否成功
     */
    @Update("update user set token = null where id = #{id}")
    int delToken(Integer id);

    /**
     * 更新密码
     *
     * @param newPassword 新密码
     * @param userId      用户id
     * @return 是否成功
     */
    @Update("update user set password = #{newPassword} where id =#{userId} ")
    int updatePassword(@Param("newPassword") String newPassword, @Param("userId") Integer userId);
}
